package com.nxy.cpfsfe.util;

import com.adtec.starring.datapool.CompSDO;
import com.adtec.starring.datapool.EPOper;
import com.adtec.starring.exception.BaseException;
import com.adtec.starring.global.SysDef;
import com.adtec.starring.respool.SystemParameter;
import com.adtec.starring.struct.dta.DtaInfo;
import com.nxy.cpfsfe.PubBeanSerial;
import com.nxy.cpfsfe.config.CpfsFeAllConfig;
import com.nxy.cpfsfe.enumtype.*;
import com.nxy.cpfsfe.mybatis.pojo.TdBatchA;
import com.nxy.cpfsfe.mybatis.pojo.TeBatchReq;
import com.nxy.cpfsfe.mybatis.service.TdBatchAService;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class ResponseUtil {
	private final static Logger LOGGER = LoggerFactory.getLogger(ResponseUtil.class);	
	
	public static  void responseSend(String bizMsg,Map map){
		String tpId = DtaInfo.getInstance().getTpId();
		// 获取输出
		CompSDO outputSdo = EPOper.getCompSDO(tpId, "RspBody"); // 获取输出接口
		EPOper.put(tpId, "RspBean[0].head[0].rspsCd",  StringUtil.trimObject(map.get("resultCode")));
		EPOper.put(tpId, "RspBean[0].head[0].respsInfoDesc", StringUtil.trimObject(map.get("msg")));
		outputSdo.setValue("BizMsg", bizMsg);
	}

	/**
	 * 通用响应报文
	 * @param map
	 * @return
	 * @throws DocumentException 
	 */
    public static  String buildXmlGeneral(Map map)  {
		LOGGER.info("---------通用响应报文--------");
		try {    		
	    	XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE,  SysDef.WORK_DIR + SystemParameter.SRC_PATH+SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"CPFS_500.xml");
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndDt", map.get("/root/MsgHeader/SndDt").toString());
	    	//报文标识
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/MsgTp",MsgCdOrTpEnum.MSGTD_500.getCode());
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/CorrId", StringUtil.trimObject(map.get("/root/MsgHeader/CorrId")));//通讯流水号
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/TrxId", StringUtil.trimObject(map.get("/root/MsgHeader/TrxId")));//交易流水
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/OriTrxId",  StringUtil.trimObject(map.get("/root/MsgHeader/OriTrxId")));//原业务流水号	
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/AcctChannel",   StringUtil.trimObject(map.get("/root/MsgHeader/AcctChannel")));
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SysRetCode",  StringUtil.trimObject(map.get("resultCode")));
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SysRetMsg",   StringUtil.trimObject(map.get("msg")));
	    	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/AcctDate", DateUtil.getDate());        
	    	xmlReqDoc.setNodeContentTrim("/root/MsgBody/Reserved", StringUtil.trimObject(map.get("Reserved")));
			LOGGER.info("通用响应报文[{}]",xmlReqDoc.dumpToBuff());
			return xmlReqDoc.dumpToBuff();
		} catch (Exception e) {
    		LOGGER.error("返回通用响应应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回通用响应应答失败");
		}

    }
    /**
     * 结算结果通知报文
     * @return
     * @throws Exception 
     */
    public  static String buildStlRstXml(TeBatchReq teBatchReq){
    	LOGGER.info("---------结算结果通知报文--------");
    	try {

        	XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH+SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"CPFS_503.xml");
        	Date date = new Date();
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndDt", DateUtil.getTimestamp(date));
        	//报文标识
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/MsgTp",MsgCdOrTpEnum.MSGTD_503.getCode());
        	//发起方系统编号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndSysId",SysEcodeEnum.CPFS.getCode());
        	//接收方系统编号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvSysId",teBatchReq.getReqSysId());
        	//发起方行号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndBankId",BnknoCdEnum.BNKNOCD_0000.getCode());
        	//接收方行号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvBankId",BnknoCdEnum.BNKNOCD_0000.getCode());
//            	PubBeanSerial pubBeanSerial = PubBeanSerial.getInstance();
//            	String  serivalNo =pubBeanSerial.getSeqNoAndIncrea(TcSequenceEnum.SEQ_STLRST_H.getCode());
        	String serivalNo = RpcCommUtil.getInstance().rpcTimerToBat(TcSequenceEnum.MSGID.getCode());
        	if(StringUtils.isBlank(serivalNo)){
        		throw new BaseException(RespCd.NCPS7001, "流水号获取失败");
        	}
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/CorrId",serivalNo);//通讯流水号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/TrxId",serivalNo);//交易流水号
        	xmlReqDoc.setNodeContentTrim("/root/MsgHeader/OriTrxId", teBatchReq.getTrxId());//原业务流水号	
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BranchId", BnknoCdEnum.BNKNOCD_0000.getCode());
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/NotifySeqNb", teBatchReq.getBatNo());
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettAmt",  StringUtil.trimObject(teBatchReq.getStlTotAmt()));

        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettBegDt", DateUtil.date2Str(teBatchReq.getCreTm(),"yyyyMMdd"));
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettEndDt", DateUtil.date2Str(teBatchReq.getProcTm(),"yyyyMMdd"));
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettNotiDt", DateUtil.date2Str(teBatchReq.getStlD(),"yyyyMMdd"));
        	xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/Remark",teBatchReq.getReqSysId()+"_"+teBatchReq.getBatNo());
        	int bStlTotDN =teBatchReq.getbStlTotDN();
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettNum",String.valueOf(teBatchReq.getStlTotDN()));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BSettNum",String.valueOf(bStlTotDN));
			if(bStlTotDN ==0){
				xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettRetCode",RespCd.NCPI0000);
			}else{
				xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/SettRetCode",RespCd.NCPO6804);
			}
			LOGGER.info("结算结果通知报文[{}]",xmlReqDoc.dumpToBuff());
    		return xmlReqDoc.dumpToBuff();
    	} catch (Exception e) {
    		LOGGER.error("返回通用响应应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回通用响应应答失败");
		}
    	

    }
	/**
     * 组装120报文
     * @param tdBatchA
     * @param teBatchReq
     * @param key true流水从联机账务获取，false，直接通用体系获取
     * @return
     */
	public static String build120Xml(TdBatchA tdBatchA, TeBatchReq teBatchReq,boolean key){
		LOGGER.info("---------120通知报文--------");
		try {
			String msgId = "";
			if(key){
				msgId = RpcCommUtil.getInstance().rpcTimerToBat(TcSequenceEnum.MSGID.getCode());
			}else{
				msgId = PubBeanSerial.getInstance().getSeqNoAndIncrea(TcSequenceEnum.MSGID.getCode());
			}
			if(StringUtils.isBlank(msgId)){
				throw new BaseException(RespCd.NCPS7001, "msgId流水号获取失败");
			}
			tdBatchA.setMsgId(msgId);
			TdBatchAService.updateTdBatchAMsgId(tdBatchA);
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH+SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_120.xml");
        	Date date = new Date();
        	String dateStr = DateUtil.date2Str(date, "yyyyMMdd");
        	String timeStr = DateUtil.date2Str(date, "HHmmss");
	   		String creDtTm = DateUtil.getISODateTime(date);
	   		 //标识本报文的报文编号	
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",MsgCdOrTpEnum.MSGCD_120.getCode());
	   		//发起系统编号NPS：农信银支付业务系统 NAS：农信银清算账户系统 NES：农信银差错处理系统
	   		//PMIS：农信银支付信息管理系统ESB：农信银企业服务总线系统MPS：成员支付业务系统CBS： 成员核心系统
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd","MPS");
//		   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd",teBatchReq.getReqSysId());
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",dateStr);
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",timeStr);
	   		//同sndAppCd规则一样
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd","NPS");
	   		//付款方都是请求方，接收方都是收款方
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",tdBatchA.getPyrBNo());
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",tdBatchA.getPyeBNo());
	   		String serivalNo = null;
	   		if(key){
	   			serivalNo = RpcCommUtil.getInstance().rpcTimerToBat(TcSequenceEnum.SEQ_NB.getCode());
	   		}else{
	   			serivalNo = PubBeanSerial.getInstance().getSeqNoAndIncrea(TcSequenceEnum.SEQ_NB.getCode());
	   		}
        	if(StringUtils.isBlank(serivalNo)){
        		throw new BaseException(RespCd.NCPS7001, "seqNb流水号获取失败");
        	}
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",serivalNo);
	   		//1.由成员单位发起的报文固定填写XML；
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
	   		//SYN：同步请求；ASYN：异步请求；
	   		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");
	   		 //报文标识号
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/MsgId", tdBatchA.getMsgId());
	   		 //报文发送时间
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/CreDtTm", creDtTm);
	   		 //明细总比数
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/NbOfTxs", "1");
	   		 //固定为CLRG
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/SttlmInf/SttlmMtd", "CLRG");
	   		 //端到端标识号先暂定为cpfs+msgId
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtId/EndToEndId",tdBatchA.getSeqNo());
	   		 //交易标识号
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtId/TxId", tdBatchA.getMsgId());
			if("2".equals(tdBatchA.getRmFlg())){
				//业务类型编码 退汇
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtTpInf/CtgyPurp/Prtry","A102");
				//业务种类，退汇标识02105
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Purp/Prtry", "02105");
				//付款行号、付款人开户行行号、行名
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/ClrSysMmbId/MmbId", StringUtil.trimObject(tdBatchA.getPyrOpenABNo()));
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/Nm", tdBatchA.getPyrBNm());
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/BrnchId/Id", StringUtil.trimObject(tdBatchA.getPyrBnakNo()));
				//付款行号、付款人开户行行号、行名
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/BrnchId/Id",StringUtil.trimObject(tdBatchA.getPyeBnakNo()));
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/ClrSysMmbId/MmbId",StringUtil.trimObject( tdBatchA.getPyeOpenABNo()));
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/Nm", tdBatchA.getPyeBNm());
			}else{
				//业务类型编码 普通汇兑
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtTpInf/CtgyPurp/Prtry","A100");
				//业务种类，汇兑标识02102
				xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Purp/Prtry", "02102");
				//付款行号、付款人开户行行号、行名
				if(StringUtils.isNotEmpty(tdBatchA.getPyrOpenABNo())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/ClrSysMmbId/MmbId", StringUtil.trimObject(tdBatchA.getPyrOpenABNo()));
				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/ClrSysMmbId/MmbId", StringUtil.trimObject(tdBatchA.getPyrBNo()));

				}
				if(StringUtils.isNotEmpty(tdBatchA.getPyrOpenABNm())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/Nm", tdBatchA.getPyrOpenABNm());
				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/Nm", tdBatchA.getPyrBNm());

				}
				if(StringUtils.isNotEmpty(tdBatchA.getPyrBnakNo())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/BrnchId/Id", StringUtil.trimObject(tdBatchA.getPyrBnakNo()));

				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/BrnchId/Id", StringUtil.trimObject(tdBatchA.getPyrBNo()));

				}

				//收款行号、收款人开户行行号、行名
				if(StringUtils.isNotEmpty(tdBatchA.getPyeBnakNo())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/BrnchId/Id",StringUtil.trimObject(tdBatchA.getPyeBnakNo()));
				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/BrnchId/Id",StringUtil.trimObject(tdBatchA.getPyeBNo()));
				}
				if(StringUtils.isNotEmpty(tdBatchA.getPyeOpenABNm())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/Nm", tdBatchA.getPyeOpenABNm());
				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/Nm", tdBatchA.getPyeBNm());
				}
				if(StringUtils.isNotEmpty(tdBatchA.getPyeOpenABNo())){
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/ClrSysMmbId/MmbId",StringUtil.trimObject( tdBatchA.getPyeOpenABNo()));
				}else{
					xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/ClrSysMmbId/MmbId",StringUtil.trimObject( tdBatchA.getPyeBNo()));
				}

			}

	   		 //货币符号、金额
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt", tdBatchA.getxAmt().toString());
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/@Ccy", "CNY");
	   		 //优先级HIGH、NORM、URGT
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/SttlmPrty", "NORM");
	   		 //固定DEBT
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/ChrgBr", "DEBT");
	   		 //付款成员行行号\ 付款行行号
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/FinInstnId/ClrSysMmbId/MmbId", tdBatchA.getPyrBNo());
	   		//收款成员行行号\  收款行行号
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/FinInstnId/ClrSysMmbId/MmbId", tdBatchA.getPyeBNo());
	   		 //付款人名称
			if(StringUtils.isEmpty(tdBatchA.getPyrNm())){
				tdBatchA.setPyrNm("0");
			}
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Dbtr/Nm", tdBatchA.getPyrNm());
			//付款人地址
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Dbtr/PstlAdr/AdrLine", "0");
			if(StringUtils.isEmpty(tdBatchA.getPyrA())){
				tdBatchA.setPyrA("0");
			}
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAcct/Id/Othr/Id", tdBatchA.getPyrA());
			//付款人开户行行号、行名
			if(StringUtils.isEmpty(tdBatchA.getPyeNm())){
				tdBatchA.setPyeNm("0");
			}
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Cdtr/Nm",tdBatchA.getPyeNm());
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Cdtr/PstlAdr/AdrLine","0");
			if(StringUtils.isEmpty(tdBatchA.getPyeA())){
				tdBatchA.setPyeA("0");
			}
	   		 xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAcct/Id/Othr/Id", tdBatchA.getPyeA());

	   		 String[] ustrds = xmlReqDoc.getNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf/Ustrd");
	   		 ustrds[0] ="/Purpose/0";
	   		 ustrds[1] ="/Remark/"+Constant.ZJGJ_FLG;
	   		 ustrds[2] ="/TransFee/0.00";
	   		 ustrds[3] ="/TranChnlTyp/07";
	   		 ustrds[4] ="/SttlmDt/"+  DateUtil.date3Str( tdBatchA.getCreTm());
			xmlReqDoc.setNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf/Ustrd",ustrds);
			if("2".equals(tdBatchA.getRmFlg())){
				 String[] orgInfoUstrds = new String[4];
				 orgInfoUstrds[0] ="/OrigMsgId/"+StringUtil.trimObject(tdBatchA.getOrgnMsgId());//退汇时填写 原报文标识号
				 orgInfoUstrds[1] ="/OrigInstgPty/"+StringUtil.trimObject(tdBatchA.getOrigInstgPty());//退汇时填写 原发起行行号
				 orgInfoUstrds[2] ="/OrgMsgCd/"+StringUtil.trimObject(tdBatchA.getOrgMsgCd());//退汇时填写   原报文编号
				 orgInfoUstrds[3] ="/RetResn/"+StringUtil.trimObject(tdBatchA.getRetResn());//退汇时填写  退汇原因
				xmlReqDoc.setNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf","Ustrd",orgInfoUstrds);
			}
	   		 xmlReqDoc.setNodeContentTrim("/transaction/signature", "");
	   		 String msg = xmlReqDoc.toString();
	   		
	   		 msg = msg.replace("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:iso:std:iso:20022:tech:xsd:NPS.120.001.01\">");
	   		 return msg;
	    
		} catch (Exception e) {
    		LOGGER.error("返回通用响应应答报文组装失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回通用响应应答报文组装失败");
		}
    	
    	
	}

	public static String build120Xml(TdBatchA tdBatchA, TeBatchReq teBatchReq){
		return build120Xml(tdBatchA, teBatchReq,true);
	}
	
	public static String buildNPS919Xml(String bizSysBNo,String chkAFNm,String starringModelNm) throws Exception{
		
		XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH + SysDef.FILE_SP + "xml" + SysDef.FILE_SP + "NPS_919.xml");

		String seqNb = "";
		String msgId = "";

		if(starringModelNm.equals("BBat")){
			seqNb = PubBeanSerial.getInstance().getSeqNoAndIncrea(TcSequenceEnum.SEQ_NB.getCode());
			msgId = PubBeanSerial.getInstance().getSeqNoAndIncrea(TcSequenceEnum.MSGID.getCode());
		}else if(starringModelNm.equals("BTmg")){
			seqNb = RpcCommUtil.getInstance().rpcTimerToBat(TcSequenceEnum.SEQ_NB.getCode());
			msgId = RpcCommUtil.getInstance().rpcTimerToBat(TcSequenceEnum.MSGID.getCode());
		}else{
			throw new Exception("Starring模块[" + starringModelNm + "]不存在");
		}

		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.date2Str(new Date(),"HHmmssSSS"));
		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",bizSysBNo);
		xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",seqNb);
		xmlReqDoc.setNodeContentTrim("/transaction/body/SysParamNtfctn/GrpHdr/MsgId",msgId);
		xmlReqDoc.setNodeContentTrim("/transaction/body/SysParamNtfctn/GrpHdr/CreDtTm",DateUtil.getISODateTime(new Date()));
		xmlReqDoc.setNodeContentTrim("/transaction/body/SysParamNtfctn/GrpHdr/InstdPty/InstdDrctPty",bizSysBNo);
		xmlReqDoc.setNodeContentTrim("/transaction/body/SysParamNtfctn/GrpHdr/InstdPty/InstdPty",bizSysBNo);
		xmlReqDoc.setNodeContentTrim("/transaction/body/SysParamNtfctn/FctvInf/FileNm",chkAFNm);
		
		String msg = xmlReqDoc.toString();
   		msg = msg.replace("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:iso:std:iso:20022:tech:xsd:NPS.919.001.01\">");
   		return msg;

	}
	
	
	public static String build911Xml(Map bizMap) throws DocumentException {
		LOGGER.info("---------报文丢弃报文--------");
    
	    try{
			// TODO 自动生成的方法存根xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ncs2:std:nps:2012:tech:xsd:NPS.900.001.01"
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_911.xml");
			Map<String, String> map = new HashMap<String, String>();
			String bizMsg="";
			
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/OrigSndr",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/OrigSndDt",(String)bizMap.get("/transaction/header/msg/sndDt")!=null?(String)bizMap.get("/transaction/header/msg/sndDt"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/MT",(String)bizMap.get("/transaction/header/msg/msgCd")!=null?(String)bizMap.get("/transaction/header/msg/msgCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/MsgId",(String)bizMap.get("/transaction/header/msg/seqNb")!=null?(String)bizMap.get("/transaction/header/msg/seqNb"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/PrcCd",(String)bizMap.get("PrcCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/DscrdMsgNtfctn/DscrdInf/RjctInf",(String)bizMap.get("RjctInf"));
			
			xmlReqDoc.setNodeContentTrim("/transaction/header/ver","02");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",MsgCdOrTpEnum.MSGCD_911.getCode());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd",(String)bizMap.get("/transaction/header/msg/rcvAppCd")!=null?(String)bizMap.get("/transaction/header/msg/rcvAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd","100000000000");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd",(String)bizMap.get("/transaction/header/msg/sndAppCd")!=null?(String)bizMap.get("/transaction/header/msg/sndAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSeqNb",(String)bizMap.get("/transaction/header/msg/seqNb")!=null?(String)bizMap.get("/transaction/header/msg/seqNb"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refCallTyp","ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refMsgCd",(String)bizMap.get("/transaction/header/msg/msgCd")!=null?(String)bizMap.get("/transaction/header/msg/msgCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndAppCd",(String)bizMap.get("/transaction/header/msg/sndAppCd")!=null?(String)bizMap.get("/transaction/header/msg/sndAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndMbrCd",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndDt",(String)bizMap.get("/transaction/header/msg/sndDt")!=null?(String)bizMap.get("/transaction/header/msg/sndDt"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/reserve",(String)bizMap.get("/transaction/header/msg/reserve")!=null?(String)bizMap.get("/transaction/header/msg/reserve"):"");
			
		
			xmlReqDoc.setNodeContentTrim("/transaction/signature","");	
			bizMsg= xmlReqDoc.toString();
			bizMsg = bizMsg!=null?bizMsg.replaceFirst("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.911.001.01\">"):"";
			LOGGER.debug("云前置FE组包911报文为：[{}]",bizMsg);
			return bizMsg;
			 
		} catch (Exception e) {
			LOGGER.error("返回911应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回911应答失败");
		}
    	
	}

	public static String build900Xml(Map bizMap) throws DocumentException {
		try{
			//xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ncs2:std:nps:2012:tech:xsd:NPS.900.001.01"
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_900.xml");
			String bizMsg="";
			xmlReqDoc.setNodeContentTrim("/transaction/header/ver","02");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",MsgCdOrTpEnum.MSGCD_900.getCode());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd",(String)bizMap.get("/transaction/header/msg/rcvAppCd")!=null?(String)bizMap.get("/transaction/header/msg/rcvAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd","100000000000");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd",(String)bizMap.get("/transaction/header/msg/sndAppCd")!=null?(String)bizMap.get("/transaction/header/msg/sndAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSeqNb",(String)bizMap.get("/transaction/header/msg/seqNb")!=null?(String)bizMap.get("/transaction/header/msg/seqNb"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refCallTyp","ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refMsgCd",(String)bizMap.get("/transaction/header/msg/msgCd")!=null?(String)bizMap.get("/transaction/header/msg/msgCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndAppCd",(String)bizMap.get("/transaction/header/msg/sndAppCd")!=null?(String)bizMap.get("/transaction/header/msg/sndAppCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndMbrCd",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndDt",(String)bizMap.get("/transaction/header/msg/sndDt")!=null?(String)bizMap.get("/transaction/header/msg/sndDt"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/reserve",(String)bizMap.get("/transaction/header/msg/reserve")!=null?(String)bizMap.get("/transaction/header/msg/reserve"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/MsgId",PubBeanSerial.getInstance().getSeqNoAndIncrea("MSGID"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/CreDtTm",DateUtil.getISODateTime(new Date()));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/InstgPty/InstgDrctPty","100000000000");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/InstgPty/InstgPty","100000000000");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/InstdPty/InstdDrctPty",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/InstdPty/InstdPty",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/GrpHdr/TranChnlTyp",(String)bizMap.get("OrgnlTranChnlTyp"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/OrgnlGrpHdr/OrgnlMsgId",(String)bizMap.get("OrgnlMsgId"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/OrgnlGrpHdr/OrgnlInstgPty",(String)bizMap.get("/transaction/header/msg/sndMbrCd")!=null?(String)bizMap.get("/transaction/header/msg/sndMbrCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/OrgnlGrpHdr/OrgnlMT",(String)bizMap.get("/transaction/header/msg/msgCd")!=null?(String)bizMap.get("/transaction/header/msg/msgCd"):"");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/OrgnlGrpHdr/OrgnlTranChnlTyp",(String)bizMap.get("OrgnlTranChnlTyp"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/CmonConfInf/PrcSts","PR01");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/CmonConfInf/PrcCd","NPSO6653");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/CmonConfInf/RjctInf","请求报文报文标识号不合法");
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/CmonConfInf/PrcDt",(String)bizMap.get("PrcDt"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/CmonConf/CmonConfInf/DrtFlg","DR01");
			xmlReqDoc.setNodeContentTrim("/transaction/signature","");
			bizMsg= xmlReqDoc.toString();
			bizMsg = bizMsg!=null?bizMsg.replaceFirst("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.900.001.01\">"):"";
			LOGGER.debug("云前置FE组包900报文为：[{}]",bizMsg);
			return bizMsg;

		} catch (Exception e) {
			LOGGER.error("返回900应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回900应答失败");
		}

	}
	public static String build303Xml(Map<String, String> bizmap) throws DocumentException {
		LOGGER.info("---------303报文--------");
    
	    try{
			// TODO 自动生成的方法存根xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ncs2:std:nps:2012:tech:xsd:NPS.303.001.01"
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_303.xml");
			String bizMsg="";
			xmlReqDoc.setNodeContentTrim("/transaction/header/ver","02");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",MsgCdOrTpEnum.MSGCD_303.getCode());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd","MPS");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",bizmap.get("sndOrgNo"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd","NPS");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",bizmap.get("recpOrgNo"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",bizmap.get("seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");

		
			xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/MsgId",bizmap.get("msgId"));
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/CreDtTm",DateUtil.getISODateTime(new Date()));
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/InstgPty/InstgDrctPty",bizmap.get("sndOrgNo"));
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/InstgPty/InstgPty",bizmap.get("sndOrgNo"));
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/InstdPty/InstdDrctPty",bizmap.get("recpOrgNo"));
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/InstdPty/InstdPty",bizmap.get("recpOrgNo"));
        	/*xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/BizTyp","");
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/BizKind","");*/
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/TranChnlTyp","06");
        	//xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/GrpHdr/Rmk","");
        	xmlReqDoc.setNodeContentTrim("/transaction/body/FreeFrmt/FreeFrmtInf/MsgCntt",bizmap.get("ntcCont"));
        	xmlReqDoc.setNodeContentTrim("/transaction/signature","");
			bizMsg= xmlReqDoc.toString();
			bizMsg = bizMsg!=null?bizMsg.replaceFirst("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.303.001.01\">"):"";
			LOGGER.debug("云前置FE组包303报文为：[{}]",bizMsg);
			return bizMsg;

			
		} catch (Exception e) {
			LOGGER.error("返回303应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回303应答失败");
		}
    	
	}
	
	public static String build990Xml(Map<String, String> map) throws DocumentException {
		LOGGER.info("---------990报文--------");
		   try{
			// TODO 自动生成的方法存根xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:ncs2:std:nps:2012:tech:xsd:NPS.990.001.01"
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_990.xml");
			String bizMsg="";
			xmlReqDoc.setNodeContentTrim("/transaction/header/ver","02");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",MsgCdOrTpEnum.MSGCD_990.getCode());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd","MPS");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",map.get("/transaction/header/msg/rcvMbrCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd",map.get("/transaction/header/msg/sndAppCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",map.get("/transaction/header/msg/sndMbrCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb"));			
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSeqNb",map.get("/transaction/header/msg/seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");			
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refCallTyp","ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refMsgCd",map.get("/transaction/header/msg/msgCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndAppCd",map.get("/transaction/header/msg/sndAppCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndMbrCd",map.get("/transaction/header/msg/sndMbrCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/refSndDt",map.get("/transaction/header/msg/sndDt"));

			xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/MsgId", map.get("/transaction/header/msg/seqNb"));
			//xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/MsgRefId", map.get("/transaction/header/msg/seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/OrigSndr",map.get("/transaction/header/msg/sndMbrCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/OrigSndDt",map.get("/transaction/header/msg/sndDt"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/MT",map.get("/transaction/header/msg/msgCd"));
			xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/MsgPrcCd","0000");
			//xmlReqDoc.setNodeContentTrim("/transaction/body/ComConf/ConfInf/Remark",map.get("Remark"));//可选项
			xmlReqDoc.setNodeContentTrim("/transaction/signature","");	
			bizMsg= xmlReqDoc.toString();
			bizMsg = bizMsg!=null?bizMsg.replaceFirst("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.990.001.01\">"):"";
			LOGGER.debug("云前置FE组包990报文为：[{}]",bizMsg);
			return bizMsg;
				
		} catch (Exception e) {
			LOGGER.error("返回990应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回990应答失败");
		}
    	
	}
	
	
	// 组装NPS.805报文
		public static String build805Xml(Map<String, String> bizmap) {
			LOGGER.info("---------系统登录/退出报文--------");
			try {

		        	XMLNodeUtil xmlReqDoc;
				    xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE,  SysDef.WORK_DIR + SystemParameter.SRC_PATH + SysDef.FILE_SP + "xml" + SysDef.FILE_SP+"NPS_805.xml");
				    Date date = new Date();
					//String seqNb = PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb");
		        	String msgId = PubBeanSerial.getInstance().getSeqNoAndIncrea("MSGID"); 
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd","MPS");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd","NPS");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd","100000000000");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",bizmap.get("seqNb"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/MsgId",msgId);
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/CreDtTm",DateUtil.getISODateTime(date));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/InstgPty/InstgDrctPty",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/InstgPty/InstgPty",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/InstdPty/InstdDrctPty","100000000000");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/InstdPty/InstdPty","100000000000");
		        	/*xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/BizTyp","");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/BizKind","");*/
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/TranChnlTyp","06");
		        	//xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/GrpHdr/Rmk","");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/LoginReq/LoginInf/LoginOprTp",bizmap.get("loginOprTp"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/signature","");
		        	String msg = xmlReqDoc.toString();	 	   		
			   		msg = msg.replace("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.805.001.01\">");
			   		return msg;

			} catch (DocumentException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
				throw new BaseException("返回登录/退出响应应答失败",e);
			}
		}
		
		// 组装NPS.903报文   
		public static String build903Xml(Map<String, String> bizmap) {
			LOGGER.info("---------数字证书绑定通知报文--------");
			try {

		        	XMLNodeUtil xmlReqDoc;
				    xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE,  SysDef.WORK_DIR + SystemParameter.SRC_PATH + SysDef.FILE_SP+"xml" + SysDef.FILE_SP+"NPS_903.xml");
				    Date date = new Date();
		        	//String seqNb = PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb"); 
		        	String msgId = PubBeanSerial.getInstance().getSeqNoAndIncrea("MSGID");
		        	LOGGER.debug("msgId=[{}]",msgId);
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd","MPS");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",DateUtil.getDate());
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",DateUtil.getTime());
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd","NPS");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd","100000000000");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",bizmap.get("seqNb"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType","XML");
		        	xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp","ASYN");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/MsgId",msgId);
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/CreDtTm",DateUtil.getISODateTime(date));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/InstgPty/InstgDrctPty",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/InstgPty/InstgPty",bizmap.get("sndOrgNo"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/InstdPty/InstdDrctPty","100000000000"); 
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/InstdPty/InstdPty","100000000000");
		        	/*xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/BizTyp","");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/BizKind","");*/
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/TranChnlTyp","06");
		        	//xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/GrpHdr/Rmk","");
		        	xmlReqDoc.setNodeContentTrim("/transaction/body/CertNtfctn/CertNtfctnInf/ChgTp",bizmap.get("bndFlg"));
		        	xmlReqDoc.setNodeContentTrim("/transaction/signature","");	        	
		        	String msg = xmlReqDoc.toString();	 	   		
			   		msg = msg.replace("<transaction>", "<transaction xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:ncs2:std:nps:2012:tech:xsd:NPS.903.001.01\">");
			   	    //将msg和chgTp放入redis
				    CpfsFeAllConfig.jedisCluster.setex(msgId, 60, bizmap.get("bndFlg")+"|"+bizmap.get("crdlDN"));
			   		return msg;

			} catch (DocumentException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
				throw new BaseException("数字证书绑定通知组装失败",e);
			}
		}

    //组501报文
	public static String build501Xml(Map<String, String> map){
		LOGGER.info("---------账务交易回执报文501报文--------");
		try{
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" +SysDef.FILE_SP+"CPFS"+ SysDef.FILE_SP+"CPFS_501.xml");
			String bizMsg="";
			//请求报文头
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndDt",DateUtil.date2Str(new Date()));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/MsgTp",MsgCdOrTpEnum.MSGTD_501.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndSysId",map.get("/root/MsgHeader/RcvSysId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvSysId",map.get("/root/MsgHeader/SndSysId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndBankId",map.get("/root/MsgHeader/RcvBankId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvBankId",map.get("/root/MsgHeader/SndBankId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/Drctn",TAbEnum.XDirn_Out.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/CorrId",map.get("/root/MsgHeader/CorrId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/TrxId",map.get("/root/MsgHeader/TrxId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/OriTrxId",map.get("/root/MsgHeader/TrxId"));
			//请求报文体
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/TrxStsCd", map.get("resultCode"));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsCd", map.get("resultCode"));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsDesc",map.get("msg"));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxId",map.get("/root/MsgHeader/TrxId"));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/MsgId","");
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/EndToEndId","");
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/SttlmDt","");
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/InstalAmt","");
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxPurpose","");
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxRemark","");
			bizMsg= xmlReqDoc.toString();
			LOGGER.debug("云前置FE组包501报文为：[{}]",bizMsg);
			return bizMsg;
		} catch (Exception e) {
			LOGGER.error("返回501应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回501应答失败");
		}

	}

	//组501报文
	public static String buildGeneral501Xml(Map<String, String> map){
		LOGGER.info("---------账务交易回执报文501报文--------");
		try{
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" +SysDef.FILE_SP+"CPFS"+ SysDef.FILE_SP+"CPFS_501.xml");
			String bizMsg="";
			//请求报文头
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndDt",DateUtil.date2Str(new Date()));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/MsgTp",MsgCdOrTpEnum.MSGTD_501.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndSysId",SysEcodeEnum.CPFS.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvSysId",StringUtil.trimObject(map.get("RcvSysId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndBankId",StringUtil.trimObject(map.get("SndBankId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvBankId",StringUtil.trimObject(map.get("RcvBankId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/Drctn",TAbEnum.XDirn_Out.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/CorrId",StringUtil.trimObject(map.get("CorrId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/TrxId",StringUtil.trimObject(map.get("TrxId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/OriTrxId",StringUtil.trimObject(map.get("OriTrxId")));
			//请求报文体
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/TrxStsCd", StringUtil.trimObject(map.get("TrxStsCd")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsCd", StringUtil.trimObject(map.get("BizStsCd")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsDesc",StringUtil.trimObject(map.get("BizStsDesc")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxId",StringUtil.trimObject(map.get("TrxId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/MsgId",StringUtil.trimObject(map.get("MsgId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/EndToEndId",StringUtil.trimObject(map.get("EndToEndId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/SttlmDt",StringUtil.trimObject(map.get("SttlmDt")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/InstalAmt",StringUtil.trimObject(map.get("InstalAmt")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxPurpose",StringUtil.trimObject(map.get("TrxPurpose")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxRemark",StringUtil.trimObject(map.get("TrxRemark")));
			bizMsg= xmlReqDoc.toString();
			LOGGER.debug("云前置FE组包501报文为：[{}]",bizMsg);
			return bizMsg;
		} catch (Exception e) {
			LOGGER.error("返回501应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回501应答失败");
		}

	}

	//组502报文
	public static String buildGeneral502Xml(Map<String, String> map) throws DocumentException {
		LOGGER.info("---------账务交易终态通知报文502报文--------");
		try{
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH +SysDef.FILE_SP+"xml" +SysDef.FILE_SP+"CPFS"+ SysDef.FILE_SP+"CPFS_502.xml");
			String bizMsg="";
			//请求报文头
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndDt",DateUtil.date2Str(new Date()));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/MsgTp",MsgCdOrTpEnum.MSGTD_502.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndSysId",SysEcodeEnum.CPFS.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvSysId",StringUtil.trimObject(map.get("RcvSysId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SndBankId",StringUtil.trimObject(map.get("SndBankId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/RcvBankId",StringUtil.trimObject(map.get("RcvBankId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/Drctn",TAbEnum.XDirn_Out.getCode());
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/CorrId",StringUtil.trimObject(map.get("CorrId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/TrxId",StringUtil.trimObject(map.get("TrxId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/OriTrxId",StringUtil.trimObject(map.get("OriTrxId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/SignSN",StringUtil.trimObject(map.get("SignSN")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/NcrptnSN",StringUtil.trimObject(map.get("NcrptnSN")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/DgtlEnvlp",StringUtil.trimObject(map.get("DgtlEnvlp")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/AcctChannel",StringUtil.trimObject(map.get("AcctChannel")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/ClbckUrl",StringUtil.trimObject(map.get("ClbckUrl")));
			xmlReqDoc.setNodeContentTrim("/root/MsgHeader/Reserved",StringUtil.trimObject(map.get("Reserved")));

			//报文体
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/TrxStsCd", StringUtil.trimObject(map.get("TrxStsCd")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsCd", StringUtil.trimObject(map.get("BizStsCd")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/BizInf/BizStsDesc",StringUtil.trimObject(map.get("BizStsDesc")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxCtgy",StringUtil.trimObject(map.get("TrxCtgy")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxId",StringUtil.trimObject(map.get("TrxId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/MsgId",StringUtil.trimObject(map.get("MsgId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/EndToEndId",StringUtil.trimObject(map.get("EndToEndId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TxNcsId",StringUtil.trimObject(map.get("TxNcsId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxAmt",StringUtil.trimObject(map.get("TrxAmt")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/SttlmDt",StringUtil.trimObject(map.get("SttlmDt")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxSysId",StringUtil.trimObject(map.get("TrxSysId")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxChnlTp",StringUtil.trimObject(map.get("TrxChnlTp")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxPurpose",StringUtil.trimObject(map.get("TrxPurpose")));
			xmlReqDoc.setNodeContentTrim("/root/MsgBody/TrxInf/TrxRemark",StringUtil.trimObject(map.get("TrxRemark")));
			bizMsg= xmlReqDoc.toString();
			LOGGER.debug("云前置FE组包502报文为：[{}]",bizMsg);
			return bizMsg;
		} catch (Exception e) {
			LOGGER.error("返回502应答失败",e);
			throw new BaseException(RespCd.NCPS2402,e,"返回502应答失败");
		}

	}
	/**
	 * 组装140报文
	 *
	 */
	public static String build140Xml(Map<String,String> map) {
		LOGGER.info("---------140报文--------");
		try {
			XMLNodeUtil xmlReqDoc = new XMLNodeUtil(XMLNodeUtil.FROM_FILE, SysDef.WORK_DIR + SystemParameter.SRC_PATH + SysDef.FILE_SP + "xml" + SysDef.FILE_SP + "NPS_140.xml");
			xmlReqDoc.setNodeContentTrim("/transaction/header/ver",                                                                 "02");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/msgCd",                                                           MsgCdOrTpEnum.MSGCD_140.getCode());
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndAppCd",                                                        map.get("/root/MsgHeader/SndSysId"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndMbrCd",                                                        map.get("/root/MsgHeader/SndBankId"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndDt",                                                           map.get("/root/MsgHeader/SndDt"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/sndTm",                                                           DateUtil.date2Str(new Date(), "HHmmss"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvAppCd",                                                        map.get("/root/MsgHeader/RcvSysId"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/rcvMbrCd",                                                        map.get("/root/MsgHeader/RcvBankId"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/seqNb",                                                           PubBeanSerial.getInstance().getSeqNoAndIncrea("seqNb"));
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/structType",                                                      "XML");
			xmlReqDoc.setNodeContentTrim("/transaction/header/msg/callTyp",                                                        "ASYN");
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/MsgId",                                        map.get("/root/MsgHeader/TrxId"));     //报文标识号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/CreDtTm",                                      map.get("/root/MsgBody/TrxInf/TrxDtTm"));     //报文发送时间
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/NbOfTxs",                                      "1");     //明细业务总笔数
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/GrpHdr/SttlmInf/SttlmMtd",                            "CLRG");                                   //固定填写CLRG
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtId/EndToEndId",                        map.get("/root/MsgBody/TrxInf/EndToEndId"));     //端到端标识号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtId/TxId",                              map.get("/root/MsgBody/TrxInf/TrxId"));     //明细标识号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/PmtTpInf/CtgyPurp/Prtry",                 map.get("/root/MsgBody/TrxInf/TrxCtgy"));     //业务类型
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt",                          map.get("/root/MsgBody/TrxInf/TrxAmt"));     //货币符号、结算金额
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/IntrBkSttlmAmt/@Ccy",                     map.get("/root/MsgBody/TrxInf/TrxCurTp"));     //
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/ChrgBr",                                  "DEBT");     //固定填写DEBT
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/FinInstnId/ClrSysMmbId/MmbId",   map.get("/root/MsgBody/PyerInf/PyerMmbId"));     //付款成员行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstgAgt/BrnchId/Id",                     map.get("/root/MsgBody/PyerInf/PyerMmbId"));     //付款行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/FinInstnId/ClrSysMmbId/MmbId",   map.get("/root/MsgBody/PyeeInf/PyeeMmbId"));     //收款成员行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/InstdAgt/BrnchId/Id",                     map.get("/root/MsgBody/PyeeInf/PyeeMmbId"));     // 收款行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Dbtr/Nm",                                 map.get("/root/MsgBody/PyerInf/PyerAcctNm"));     //付款人名称
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Dbtr/PstlAdr/AdrLine",                    map.get("/root/MsgBody/PyerInf/PyerAddr"));     //付款人地址
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAcct/Id/Othr/Id",                     map.get("/root/MsgBody/PyerInf/PyerAcctNo"));     //付款人账号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/ClrSysMmbId/MmbId",    map.get("/root/MsgBody/PyerInf/PyerBrnchId"));     //付款人开户行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/DbtrAgt/FinInstnId/Nm",                   map.get("/root/MsgBody/PyerInf/PyerBrnchNm"));     //付款人开户行名称
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/ClrSysMmbId/MmbId",    map.get("/root/MsgBody/PyeeInf/PyeeBrnchId"));     //收款人开户行行号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAgt/FinInstnId/Nm",                   map.get("/root/MsgBody/PyeeInf/PyeeBrnchNm"));     //收款人开户行名称
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Cdtr/Nm",                                 map.get("/root/MsgBody/PyeeInf/PyeeAcctNm"));     //收款人名称
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Cdtr/PstlAdr/AdrLine",                    map.get("/root/MsgBody/PyeeInf/PyeeAddr"));     // 收款人地址
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/CdtrAcct/Id/Othr/Id",                     map.get("/root/MsgBody/PyeeInf/PyeeAcctNo"));     //收款人账号
			xmlReqDoc.setNodeContentTrim("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/Purp/Prtry",                              map.get("/root/MsgBody/TrxInf/BizKind"));     //业务种类编码

			String[] ustrds = xmlReqDoc.getNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf/Ustrd");
			ustrds[0] = "/Postscript/"+map.get("/root/MsgBody/TrxInf/TrxPurPose");   //附言
			ustrds[1] = "/Remark/"+map.get("/root/MsgBody/TrxInf/TrxRemark"); // 备注
			ustrds[2] = "/OrigMsgId/"+ map.get("/root/MsgBody/RmtInf/OriTrxId");  // 原报文标识号
			if(StringUtils.isNotBlank(map.get("/root/MsgBody/TrxInf/TrxFeeAmt"))){
				ustrds[3] = "/TransFee/"+map.get("/root/MsgBody/TrxInf/TrxFeeAmt");// 代理行手续费
			}else {
				ustrds[3] = "/TransFee/0.00";
			}
			ustrds[4] = "/TranChnlTyp/07";//交易渠道类型
			ustrds[5] = "/SttlmDt/"+map.get("/root/MsgBody/PyeeInf/CardSeqId");//清算日期/终态日期
			ustrds[6] = "/PayerAccTyp/"+map.get("/root/MsgBody/PyerInf/PyerAcctTp");         //付款人账户类型
			ustrds[7] = "/PayeeAccTyp/"+map.get("/root/MsgBody/PyeeInf/PyeeAcctTp");           // 收款人账户类型
			ustrds[8] = "/Track2Data/"+map.get("");            //第二磁道数据
			ustrds[9] = "/Track3Data/"+map.get("");        //第三磁道数据
			ustrds[10] = "/PsBkBlcAmt/"+map.get("/root/MsgBody/RmtInf/PsBkBlcAmt");       //存折余额
			ustrds[11] = "/PsBkNo/"+map.get("/root/MsgBody/RmtInf/PsBkNo");          //存折号码
			//收款人账户类型为“IC卡” 时有以下附加数据域
			if("PT05".equals(map.get("/root/MsgBody/PyeeInf/PyerAcctTp"))||"PT06".equals(map.get("/root/MsgBody/PyeeInf/PyerAcctTp"))){//PT02 单位银行结算账PT03 磁条借记卡PT04 磁条贷记卡PT05 IC借记卡PT06 IC贷记卡
				String[] ustrdIcs = new String[5];
				ustrdIcs[0] = "/CardSeqId/"+map.get("/root/MsgBody/PyeeInf/CardSeqId");                 //卡序列号
				ustrdIcs[1] = "/PANEtrModCd/"+map.get("/root/MsgBody/PyeeInf/PANEtrModCd");                 //IC卡PAN输入方式
				ustrdIcs[2] = "/TerEC/"+map.get("/root/MsgBody/PyeeInf/TerEC");                 //终端读取能力
				ustrdIcs[3] = "/ICCndCd/"+map.get("/root/MsgBody/PyeeInf/ICCndCd");                 //IC卡条件代码
				ustrdIcs[4] = "/ICCData/"+map.get("/root/MsgBody/PyeeInf/ICCData");                 //IC卡数据域
				xmlReqDoc.setNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf","Ustrd",ustrdIcs);     //业务种类编码

			}
			//由支付机构发起的代付、提现、退货等业务时，有以下附加字段：
			//待完善
			if("A102".equals(StringUtil.trimObject(map.get("/root/MsgBody/TrxInf/TrxCtgy")))){
				String[] ustrdRefunds = new String[18];
				ustrdRefunds[0] = "/TrxTp/"+map.get("/root/MsgBody/TrxInf/TrxCtgy");      //交易类型           //2000-转账 2001-信用卡还款 2004-退货 2005-提现 2006-理财赎回 4000-其他
				ustrdRefunds[1] = "/SgnNo/"+map.get("/root/MsgBody/RmtInf/SgnNo");                 //签约协议号
				ustrdRefunds[2] = "/PayerAcctIssrId/"+map.get("/root/MsgBody/RmtInf/PayerAcctIssrId");                 //付款方账户所属机构标识
				ustrdRefunds[3] = "/InstgTrxTrmTp/"+map.get("/root/MsgBody/RmtInf/InstgTrxTrmTp");                 //发起方交易终端类型  //01–电脑 02–手机 03-平板设备 04-可穿戴设备 05数字电视 06-条码支付受理终端 99-其他
				ustrdRefunds[4] = "/PayeeAcctIssrId/"+map.get("/root/MsgBody/RmtInf/PayeeAcctIssrId");                 //收款方账户所属机构标识
				ustrdRefunds[5] = "/InstgId/"+map.get("/root/MsgBody/RmtInf/InstgId");                 //非银行支付机构标识
				ustrdRefunds[6] = "/InstgAcctId/"+map.get("/root/MsgBody/RmtInf/InstgAcctId");                 //非银行支付机构备付金账户
				ustrdRefunds[7] = "/InstgAcctIssrId/"+map.get("/root/MsgBody/RmtInf/InstgAcctIssrId");                 //备付金账户所属机构标识
				ustrdRefunds[8] = "/OriTrxId/"+map.get("/root/MsgBody/RmtInf/OriTrxId");                 //原交易流水号
				ustrdRefunds[9] = "/OriBkTrxId/"+map.get("/root/MsgBody/RmtInf/OriBkTrxId");                 //原银行流水号
				ustrdRefunds[10] = "/PyerMrchntNo/"+map.get("/root/MsgBody/RmtInf/PyerMrchntNo");                 //付款商户编号
				ustrdRefunds[11] = "/PyerMrchntNm/"+map.get("/root/MsgBody/RmtInf/PyerMrchntNm");                 //付款商户名称
				ustrdRefunds[12] = "/PyerMrchntShrtNm/"+map.get("/root/MsgBody/RmtInf/PyerMrchntShrtNm");                 //付款商户简称
				ustrdRefunds[13] = "/OriTrxAmt/"+map.get("/root/MsgBody/RmtInf/OriTrxAmt");                 //原交易金额
				ustrdRefunds[14] = "/TrxSmmry/"+map.get("");                 //交易摘要
				ustrdRefunds[15] = "/InstgTrxTrmNo/"+map.get("/root/MsgBody/RmtInf/InstgTrxTrmNo");                 //发起方交易终端编码
				ustrdRefunds[16] = "/TrxDevcInf/"+map.get("/root/MsgBody/RmtInf/TrxDevcInf");                 //交易设备信息
				ustrdRefunds[17]= "/BatchId/"+map.get("/root/MsgBody/RmtInf/BatchId");                 //批次号
				xmlReqDoc.setNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf","Ustrd",ustrdRefunds);     //业务种类编码

			}
			//01、05渠道发起的个人通存请求，且业务种类为“03302 转账”时，有以下附加域，且均为必填项。
			//待完善
			if("03302".equals(StringUtil.trimObject(map.get("/root/MsgBody/TrxInf/BizKind")))){
				String[] ustrd03302s = new String[3];
				ustrd03302s[0] = "/CertTyp/"+map.get("");                    //付款人证件类型
				ustrd03302s[1] = "/PayerIDInfo/"+map.get("");                 //付款人摘要信息
				ustrd03302s[2] = "/DelayType/"+map.get("");                 //转入实时标记
				xmlReqDoc.setNodesContent("/transaction/body/FIToFICstmrCdtTrf/CdtTrfTxInf/RmtInf","Ustrd",ustrd03302s);     //业务种类编码
			}
			xmlReqDoc.setNodeContentTrim("/transaction/signature","1");
			return xmlReqDoc.toString();
		} catch (Exception e) {
			LOGGER.error("140报文报文组装失败", e);
			throw new BaseException(RespCd.NCPS2402, e, "140报文报文组装失败");
		}


	}





}
